public class ArrayTest {

    static public int [] show(int [] a) {
        int l = 0;
        for (int i : a) {
            System.out.printf("a[%d] = %d\n", l++, i);
        }

        return a;
    }

    static public int [] rand(int [] a) {
        for (int i = 0; i < a.length; ++i) {
            a[i] = (int)(Math.random() * 101 + 50);
        }
        return a;
    }

    static public int [] init(int len, int ... data) {
        int dl = data.length;

        if (len == 0 && data.length == 0)
            return null;

        int [] a = new int[dl > len ? dl : len];

        if (dl != 0) {
            for (int i = 0; i < dl; ++i) {
                a[i] = data[i];
            }
        }

        return a;
    }

    static public void main(String [] args) {
        // int a[];             //声明
        // a = new int[10];     //实例化
        //
        // int a[] = new int[10];  //声明实例化
        // int a[] = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        // int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        // int a[] = init(10);

        // a[3] = 99;
        // a[6] = 67;

        // System.out.printf("a.length = %d\n", a.length);
        //
        // show(init(0, 1, 2, 3, 4, 5));
        // show(rand(init(10)));

        int [] a = {1, 2, 3, 4, 5, 6};
        // int [] b = a;
        int [] b = new int[10];
        System.arraycopy(a, 0, b, 0, a.length);

        b[1] = 999;

        show(a);
        System.out.printf("b:\n");
        show(b);

    }
}
